package com.yonyou.struts2demo.form;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author wwj
 * @Date 2021/12/10
 * @Description 获取表单数据第二种 ServletActionContext
 */
public class FormSecondAction extends ActionSupport {

    @Override
    public String execute() throws Exception {
        // 第二种方式，使用 ServletActionContext 获取
        // 1 使用 ServletActionContext 获取request对象
        HttpServletRequest request = ServletActionContext.getRequest();
        // 2 调用 request 里面的方法得到结果
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String address = request.getParameter("address");

        System.out.println(username + ":" + password + ":" + address);
        return NONE;
    }
}
